/***************************************
 *File name: Student.c                 *
 *Author: Gu Zhengxiong                *
 *Version: 2013.11.23.1                *
 *Description:The file implements      *
 *functions in STUDENT.h               *
 ***************************************/

# include <stdio.h>
# include <stdlib.h>
# include <string.h>

# include "StudentInfo.h"
# include "StudentGrade.h"
# include "Student.h"
# include "MainFace.h"
# include "Manip.h"//For Inquire ().


void
DisplayInfoPs (PSTUDENT ps)
{
	
	printf ("\n      THE STUDENT'S DETAILED INFORMATION\n");
	printf ("      NAME: %s\n", ps->pi->name);
	printf ("      NUMBER: %s\n", ps->pi->number);
	if (ps->pi->gender == 1)
		printf ("      GENDER: %s\n", "MALE");
	else
		printf ("      GENDER: %s\n", "FEMALE");
	printf ("      AGE: %d\n", ps->pi->age);
	printf ("      ADDRESS: %s\n", ps->pi->address);
}
void
DisplayGradePs (PSTUDENT ps)
{
	printf ("\n      THE STUDENT'S DETAILED GRADE\n");
	printf ("      MATHS: %g\n", ps->pg->maths);
	printf ("      CLANG: %g\n", ps->pg->clang);
	printf ("      ENGLISH: %g\n", ps->pg->english);
	printf ("      TOTAL: %g\n", ps->pg->clang + ps->pg->english + ps->pg->maths);
	printf ("      AVERAGE: %.2lf\n", (ps->pg->clang + ps->pg->english + ps->pg->maths) / 3.0);
}
void
DestroyPs (PSTUDENT ps_before)
{
	free (ps_before->pnext->pg);
	free (ps_before->pnext->pi);
	ps_before->pnext = ps_before->pnext->pnext;
}
void
ModifyInfo (PSTUDENT ps, PSTUDENT phead)// I checked noting.
{
	int mod_flag;
	ps->DisplayInfoPs (ps);
	printf ("\n      WHICH INFORMATION TO VARY?\n      1 FOR NMAE and 2 FOR NUMBER\n");
	printf ("      3 FOR GENDER AND 4 FOR AGE\n      5 FOR ADDRESS AND 0 FOR NOTIHNG\n");
	printf ("\n      ENTER A NUMBER: ");
	scanf ("%d", &mod_flag);
	switch (mod_flag)
	{
		case 0 : break;
		case 1: 
			{
				char name_buf[16];
				printf ("\n      ENTER A NEW NAME: ");
				getchar ();
				gets (name_buf);
				if (Inquire (phead, SEARCH_NAME, name_buf) != NULL)
				{
					ShowError (EXISTED);
					break;
				}
				strcpy (ps->pi->name, name_buf);
				printf ("\n      MODIFICATION OVER.\n");
				Enter2Retn1 ();
			}
			break;
		case 2:
			{
				char number_buf[16];
				printf ("\n      ENTER A NEW NUMBER: ");
				scanf ("%s", number_buf);
				if (Inquire (phead, SEARCH_NUM, number_buf) != NULL)
				{
					ShowError (EXISTED);
					break;
				}
				strcpy (ps->pi->number, number_buf);
				printf ("\n      MODIFICATION OVER.\n");
				Enter2Retn ();
			}
			break;
		case 3:
			{
				printf ("\n      ENTER A NEW GENDER: ");
				scanf ("%d", &(ps->pi->gender));
				printf ("\n      MODIFICATION OVER.\n");
				Enter2Retn ();
			}
			break;
		case 4:
			{
				printf ("\n      ENTER A NEW AGE: ");
				scanf ("%d", &(ps->pi->age));
				printf ("\n      MODIFICATION OVER.\n");
				Enter2Retn ();
			}
			break;
		case 5:
			{
				printf ("\n      ENTER A NEW ADDRESS: ");
				getchar ();
				gets (ps->pi->address);
				printf ("\n      MODIFICATION OVER.\n");
				Enter2Retn ();
			}
			break;
		default: ShowError (IN_ERR); break;
	}
}
void
ModifyGrade (PSTUDENT ps)//I checked nothing.
{
	int mod_flag;
	ps->DisplayGradePs (ps);
	printf ("\n      WHICH GRADE TO CHANGE?\n      1 FOR MATHS AND 2 FOR CLANG\n");
	printf ("      3 FOR ENGLISH AND 0 FOR NOTING\n");
	printf ("\n      ENTER A NUMBER:");
	scanf ("%d", &mod_flag);
	switch (mod_flag)
	{
		case 0: break;
		case 1:
			{
				printf ("\n      ENTER A NEW MATHS SCORE: ");
				scanf ("%lf", &(ps->pg->maths));
				printf ("\n      CHANGE ACCOMPLISHED\n");
				Enter2Retn ();//
			}
			break;
		case 2:
			{
				printf ("\n      ENTER A NEW CLANG SCORE: ");
				scanf ("%lf", &(ps->pg->clang));
				printf ("\n      CHANGE ACCOMPLISHED\n");
				Enter2Retn ();//
			}
			break;
		case 3:
			{
				printf ("\n      ENTER A NEW ENGLISH SCORE: ");
				scanf ("%lf", &(ps->pg->english));
				printf ("\n      CHANGE ACCOMPLISHED\n");
				Enter2Retn ();//
			}
			break;
		default: ShowError (IN_ERR); break;
	}
}